import {defineStore} from "pinia"
import {login} from "@/service/api"
import {commons} from "@/utils/commons";

// 定义state类型 (也可以不定义)
interface AuthState {
    userInfo: {} | null
    token: string | null
}

export const useAuthStore = defineStore("auth", {
    state: (): AuthState => ({
        userInfo: uni.getStorageSync('userInfo') || null,
        token: null,
    }),
    actions: {
        // 用户登录
        async userLogin(params: object) {
            await login(params).then(res => {
                this.token = res.data.token
                this.setStorage(res.data.token)
            })
        },

    }
})
